package io.renren.modules.dataInitialization.controller;


import io.renren.common.exception.RRException;
import io.renren.common.utils.R;
import io.renren.modules.dataInitialization.service.PersonnelDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("PersonnelData/")
public class PersonnelDataController {
    @Autowired
    PersonnelDataService personnelDataService;
    @RequestMapping("/ExcelImport/Teacher")
    public R uploadTeacher(@RequestParam("file") MultipartFile file) throws Exception {
        //这里只写了elx一种，就是excel2003-2007这个版本的， 别用错了
        if (file.isEmpty()) {
            throw new RRException("上传文件不能为空");
        }
        personnelDataService.dataImportTeacher(file.getInputStream());
        return R.ok().put("msg", "数据导入成功");
    }
    @RequestMapping("/ExcelImport/Student")
    public R uploadStudent(@RequestParam("file") MultipartFile file) throws Exception {
        //这里只写了elx一种，就是excel2003-2007这个版本的， 别用错了
        if (file.isEmpty()) {
            throw new RRException("上传文件不能为空");
        }
        personnelDataService.dataImportStudent(file.getInputStream());
        return R.ok().put("msg", "数据导入成功");
    }
    @RequestMapping("/ExcelImport/CollegeInfo")
    public R uploadCollege(@RequestParam("file") MultipartFile file) throws Exception {
        //这里只写了elx一种，就是excel2003-2007这个版本的， 别用错了
        if (file.isEmpty()) {
            throw new RRException("上传文件不能为空");
        }
        personnelDataService.dataImportCollegeInfo(file.getInputStream());
        return R.ok().put("msg", "数据导入成功");
    }
}
